/** 错误搜集模块 */

/**
 * 
 * @param {*} filePath 
 * @param {*} lineno 
 * @param {*} message 
 * @param {*} stack 
 */

window.__errorHandler = function (filePath, lineno, message, stack) {
    GameData.errorNum += 1;
    if (GameData.errorNum <= 10) return;

    if (GameData.isErrorHandler) return;
    GameData.isErrorHandler = true;
    GameData.errorNum = 0;

    let errorData = JSON.stringify({filePath, lineno, message, stack});
    console.warn('捕获异常 ==>', errorData);

    // "message" :"Uncaught TypeError: Cannot read property 'x' of undefined","stack":
    let errorList = [
        "Uncaught TypeError: Cannot read property 'x' of undefined",
        "[0]update@assets/main/index.",
        "[1]eval@(no filename):",
        "[2]anonymous@src/cocos2d-jsb.",
        "[3]invoke@src/cocos2d-jsb.",
        "[4]updatePhase@src/cocos2d-jsb.",
        "[5]mainLoop@src/cocos2d-jsb.",
        "[6]t@src/cocos2d-jsb.",
        "[7]tick@jsb-adapter/jsb-builtin.js:2160"
    ];
    let num = 0;
    errorList.forEach(str => {
        if (errorData.includes(str)) num += 1;
    })
    if (num >= errorList.length) {
        cc.warn('找到相同报错点');
        errorData = JSON.stringify({alike: true, filePath, lineno, message, stack});
    }

    // PlatformManager.instance.onEventError('1', errorData);

    // Loader.loadPrefab(['errorHandlerPanel'], ()=>{}, (asserts)=>{
    //     console.warn('捕获异常面板加载成功 ==>');
    //     let newNode = Loader.loadNode(asserts[0], cc.find("Canvas/Game"), cc.v2(0, 0), 1000);
    //     console.error('newNode =>>', !!newNode);
    //     newNode.js && newNode.js.initData({ errorData });
    // })
}
